package aaaaa;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class MyDelayOrder implements Delayed {

    private String name;
    private long availableTime;

    public MyDelayOrder(String name, Long availableTime) {
        this.name = name;
        this.availableTime = availableTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getAvailableTime() {
        return availableTime;
    }

    public void setAvailableTime(long availableTime) {
        this.availableTime = availableTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        //判断availableTime是否大于当前系统时间，并将结果转换成MILLISECONDS
        long diffTime = availableTime - System.currentTimeMillis();
        return unit.convert(diffTime, TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        //compareTo用在DelayedUser的排序
        return (int) (this.availableTime - ((MyDelayOrder) o).getAvailableTime());
    }
}
